package com.lf.web.service.system.module;

import com.lf.data.*;
import org.json.JSONObject;

import java.util.Map;

public class Module extends Cluster {

    /**
     *
     */
    private static final long serialVersionUID = 644512643819115523L;

    @Key(keyType = KeyType.MapKey, valueType = ValueType.String, check = "^[\\s\\w\u4e00-\u9fa5]{1,50}$", nullable = false)
    public static final String TITLE = "title";

    @Key(keyType = KeyType.MapKey, valueType = ValueType.String, check = "^.{1,20}$", nullable = false)
    public static final String EXT_KEY = "extKey";

    @Key(keyType = KeyType.MapKey, valueType = ValueType.Integer, check = Validate.INTEGER, nullable = false)
    public static final String INDEX = "index";

    @Key(keyType = KeyType.MapKey, valueType = ValueType.String, check = "^.+$", nullable = false)
    public static final String OPTION = "option";

    public static final String CHANNEL = "webnode";

    /**
     * 取可是（*+-!）<br />
     * <b>*</b> 表示任意值页面<br /><b>+</b> 表示选定页面<br /><b>-</b> 表示选定页面除外<br /><b>!</b> 表示不显示
     */
    @Key(keyType = KeyType.MapKey, valueType = ValueType.String, check = "^[\\*\\+\\-!]$", nullable = true)
    public static final String CHANNEL_ALL = "webnode.all";

    @Key(keyType = KeyType.ListKey, valueType = ValueType.String, check = Validate.OBJECTID, nullable = true)
    public static final String CHANNEL_LIST = "webnode.list";

    @Key(keyType = KeyType.MapKey, valueType = ValueType.String, check = "^\\w+$", nullable = true)
    public static final String POSITION = "position";

    public static final String EXT = "ext";

    public static final String UPDATED = "updated";

    public static final String CREATED = "created";

    public Module() {
        super();
    }

    public Module(Map<String, Object> map) {
        super(map);
    }

    public void formatOption() {
        String option = getString(this.OPTION);
        try {
            JSONObject jo = new JSONObject(option);
            this.put(this.OPTION, jo);
        } catch (Exception e) {
            this.put(this.OPTION, new JSONObject());
        }
    }
}
